
function analyzeLaiiSigGUI()

    workingDir = 'C:\Users\rniehaus\Documents\Elegans\';
    filter = sprintf('%s*.proj', workingDir);
    [fileName,pathName,filterIndex] = uigetfile(filter);
     studyInstanceName = fileName(1:length(fileName) - 5);
    [data, suppData] = getStudyInstance(workingDir, studyInstanceName);
    analyzeLaiiSig( suppData, data);
    
    
    function  analyzeLaiiSig( suppData, data)
    %UNTITLED Summary of this function goes here
    %   Detailed explanation goes here

        curFrame = 1;
        nFrames = length(suppData);
        fy = figure('Name','LAII Signature Analysis','NumberTitle','off');
        scrsz = get(0,'ScreenSize');
        set(fy,'Position',[1 1 0.9*scrsz(3) 0.9*scrsz(4)]);


        bh1 = uicontrol(fy,'Position',[600 100 60 30],...
                        'String','Next',...
                        'Callback',@button_next);


        bh2 = uicontrol(fy,'Position',[680 100 60 30],...
                        'String','Previous',...
                        'Callback',@button_previous);   

        ax_bwImage = axes('Parent',fy,'units','pixels',...
                   'Position',[25 220 400 600]);
        ax_LaiiSig = axes('Parent',fy,'units','pixels',...
                   'Position',[650 220 400 600]);
        ax_LaiiEnds = axes('Parent',fy,'units','pixels',...
                   'Position',[1075 220 400 600]);


       updateDisplay()
     %------------------------------------------------

       function button_next(hObject,eventdata)
            if curFrame ~= nFrames
               curFrame = curFrame + 1;
           end
           updateDisplay()
       end
       %------------------------------------------------
       function button_previous(hObject,eventdata)
           if curFrame ~= 1
               curFrame = curFrame - 1;
           end
           updateDisplay()
       end


        function updateDisplay()

            bwImage = suppData(curFrame).BwImage;
            kernelRadius = 20;
            sigma = 1;
            threshold = 0.6;
            [theEnds, signal]= getEndpointsFromCurvature( bwImage, kernelRadius, sigma, threshold, 1);
             
            
            %Overlay large dots at the endpoints 
            indices = [];
            for i = 1:size(theEnds,1)
                dotIndices = getDotIndices(size(bwImage),theEnds(i,:) ,5);
               indices = [indices; dotIndices];

            end
            rgbImage = gray2rgb(bwImage);
            rgbImage = applyOverlay(rgbImage, indices, 'red' );
            rgbImage = cropFromCentroid(rgbImage, ...
                          [ data(curFrame).CentroidRow, ...
                            data(curFrame).CentroidCol],...
                          [300,300]);

            imshow(rgbImage, 'Parent', ax_bwImage);
            
            plot(ax_LaiiSig, signal);
            
            headRow = data(curFrame).HeadRow;
            headCol = data(curFrame).HeadCol;
           
            tailRow = data(curFrame).TailRow;
            tailCol = data(curFrame).TailCol;
            pixelA = [headRow, headCol];
            pixelB = [tailRow,tailCol];
             curvDiff = compareCurvature( bwImage, pixelA, pixelB, kernelRadius );
            bar(ax_LaiiEnds,[curvDiff]);
        end

    end
end


